﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dimac.JMail;

namespace Hisuntech.SystemFramework.Net.Mail
{
    public class JMailNet : Emails
    {
        public override bool Send(WcfMail.Interface.ISysMsg message)
        {
            bool flag = false;
            Message curmsg = new Message();
            MailInfos mailInfo = (MailInfos)message;
           
            //curmsg.MailServerUserName = mailInfo.ServerUsername; //message.ServerUsername;
            //curmsg.MailServerPassWord = mailInfo.ServerPassword;
            curmsg.From.Email  = mailInfo.MailFrom;
            curmsg.Subject = mailInfo.MsgSubject;
            curmsg.Charset = System.Text.Encoding.Default;
            //curmsg.Priority = mailInfo.IPriority;
            curmsg.BodyText  = mailInfo.MsgContent;//发送邮件之前对内容进行压缩
            AddressList address = new AddressList();
            address.Add(mailInfo.MailTo, "dth");
            curmsg.To = address;
            //curmsg.ISOEncodeHeaders = false;
            //curmsg.ContentType = "text/plain";
            //if (mailInfo.IsAttachment)
            //    curmsg.AddAttachment(mailInfo.AttachmentPath, true, null);

            try
            {
                Dimac.JMail.Smtp smtp = new Smtp();
                smtp.Domain = mailInfo.MailServer;
                smtp.HostName = mailInfo.MailServer;
                smtp.Port = 25;
                smtp.UserName = mailInfo.ServerUsername;
                smtp.Password = mailInfo.ServerPassword;
                smtp.LogStream = Console.OpenStandardOutput();
                smtp.Authentication = SmtpAuthentication.Login;
                smtp.Send(curmsg);
               
            
               // Smtp.Send(curmsg, mailInfo.MailServer,25,mailInfo .MailServer,SmtpAuthentication.Login  ,mailInfo.ServerUsername ,mailInfo.ServerPassword );
                flag = true;  
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
                flag = false;
            }
            return flag;
        }

        public override bool Receive(WcfMail.Interface.ISysMsg message)
        {
            throw new NotImplementedException();
        }
    }
}
